var t = require("../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        keywork: "",
        active: 0,
        show: !1,
        info: [],
        labelSelect: 0,
        poplabel: "",
        popupList: [],
        popupPage: 1,
        popupLast: 1,
        posterShow: !1,
        posterData: {
            poster_data: null,
            background: {}
        },
        defaultImg: "",
        showPosterInd: 0,
        fmPosterShow: !1,
        childImgaeBase: "",
        leftImg: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FposterCenter%2Fleft.png",
        leftImg1: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FposterCenter%2Fleft2.png",
        rightImg: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FposterCenter%2Fright.png",
        rightImg1: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/images%2FposterCenter%2Fright2.png",
        is_record: !1,
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        wx.setNavigationBarTitle({
            title: "海报中心"
        }), this.getData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore && this.getMoreData();
    },
    onShareAppMessage: function() {},
    showInIint: function(a) {
        var e;
        this.setData((t(e = {
            show: a,
            popupPage: 1,
            popupLast: 1
        }, "popupLast", 1), t(e, "popupList", []), e));
    },
    showInMethod: function() {
        var t = this;
        this.showInIint(!0), this.setData({
            poplabel: this.data.labelSelect
        });
        var e = a.getNetAddresss("plugin.poster-center.frontend.controllers.index.getLabel");
        a._getNetWork({
            url: e,
            data: {
                page: this.data.popupPage
            },
            success: function(a) {
                var e = a.data;
                1 == e.result && t.setData({
                    popupList: e.data.list.data,
                    popupLast: e.data.list.last_page
                });
            }
        });
    },
    popupMore: function() {
        var t = this;
        if (!(this.data.popupPage >= this.data.popupLast)) {
            this.setData({
                popupPage: this.data.popupPage + 1
            });
            var e = a.getNetAddresss("plugin.poster-center.frontend.controllers.index.getLabel");
            a._getNetWork({
                url: e,
                data: {
                    page: this.data.popupPage
                },
                success: function(a) {
                    var e = a.data;
                    1 == e.result && t.setData({
                        popupList: t.data.popupList.concat(e.data.list.data)
                    });
                }
            });
        }
    },
    cancelTap: function() {
        this.setData({
            poplabel: this.data.labelSelect
        }), this.showInIint(!1);
    },
    confirmTap: function() {
        this.setData({
            labelSelect: this.data.poplabel
        }), this.showInIint(!1), this.getData();
    },
    chooseTag: function(t) {
        var a = t.currentTarget.dataset.item;
        this.data.poplabel != a.id ? this.setData({
            poplabel: a.id
        }) : this.setData({
            poplabel: 0
        });
    },
    creatPoster: function() {
        var t = this;
        this.setData({
            posterData: {
                poster_data: null,
                background: {}
            }
        });
        var e = this.data.info.poster_list.data[this.data.showPosterInd].id, s = a.getNetAddresss("plugin.poster-center.frontend.controllers.index.createPoster");
        a._getNetWork({
            url: s,
            data: {
                poster_id: e
            },
            success: function(a) {
                var e = a.data;
                1 == e.result && (t.setData({
                    posterShow: !0,
                    is_record: e.data.is_record
                }), e.data.is_record ? (t.data.info.poster_list.data[t.data.showPosterInd].background_poster_url = e.data.url, 
                t.setData({
                    defaultImg: e.data.url
                })) : (t.data.posterData.background.type = "background", t.data.posterData.background.src = e.data.model && e.data.model.background ? e.data.model.background : "", 
                t.data.posterData.poster_data = e.data.model && e.data.model.style_data ? e.data.model.style_data : [], 
                console.log(t.data.posterData, "dddddddd"), t.setData({
                    defaultImg: "",
                    posterData: t.data.posterData
                })), console.log(e));
            }
        });
    },
    finish: function(a) {
        console.log(a);
        var e = a.detail;
        this.setData(t({
            childImgaeBase: e
        }, "info.poster_list.data[" + this.data.showPosterInd + "].background_poster_url", e)), 
        this.data.is_record || this.uoloadPoster();
    },
    uoloadPoster: function() {
        var t = this, e = wx.getStorageSync("wx_token"), s = wx.getStorageSync("session"), o = a.getNetAddresss("plugin.poster-center.frontend.controllers.index.uploadLocal");
        o += "&poster_id=" + this.data.info.poster_list.data[this.data.showPosterInd].id, 
        o += "&3rd_session=" + s, o += "&ingress=ingress", wx.uploadFile({
            url: o,
            filePath: this.data.info.poster_list.data[this.data.showPosterInd].background_poster_url,
            name: "file",
            formData: {
                _wx_token: wx.getStorageSync("wx_token"),
                ingress: 0
            },
            header: {
                "Content-Type": "multipart/form-data",
                Cookie: "PHPSESSID=" + e
            },
            success: function(a) {
                var e = JSON.parse(a.data);
                1 == e.result && t.addPosterRecord(e.data.img_url);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    addPosterRecord: function(t) {
        var e = a.getNetAddresss("plugin.poster-center.frontend.controllers.index.posterRecord");
        a._postNetWork({
            url: e,
            data: {
                image: t,
                poster_id: this.data.info.poster_list.data[this.data.showPosterInd].id
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? console.log(e) : a.tips(e.msg);
            }
        });
    },
    showPoster: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.index;
        this.setData({
            showPosterInd: a,
            fmPosterShow: !0
        });
    },
    closeFm: function() {
        this.setData({
            defaultImg: [],
            fmPosterShow: !1
        });
    },
    scrollLeft: function() {
        0 != this.data.showPosterInd ? this.data.showPosterInd > 0 && this.setData({
            showPosterInd: Number(this.data.showPosterInd) - 1
        }) : a.tips("已经是第一张");
    },
    scrollRight: function() {
        this.data.showPosterInd >= this.data.info.poster_list.data.length - 1 ? a.tips("已经是最后一张") : this.data.showPosterInd < this.data.info.poster_list.data.length && this.setData({
            showPosterInd: Number(this.data.showPosterInd) + 1
        });
    },
    searchMethod: function(t) {
        this.setData({
            keywork: t.detail
        }), this.getData();
    },
    tapType: function(t) {
        var a = t.currentTarget.dataset.id;
        this.setData({
            active: a
        }), this.getData();
    },
    tapLabel: function(t) {
        var a = t.currentTarget.dataset.id;
        this.setData({
            labelSelect: a
        }), this.getData();
    },
    getData: function() {
        var t = this, e = {
            poster_type: this.data.active ? this.data.active : "",
            title: this.data.keywork ? this.data.keywork : "",
            label_id: this.data.labelSelect ? this.data.labelSelect : ""
        }, s = a.getNetAddresss("plugin.poster-center.frontend.controllers.index.index");
        a._getNetWork({
            url: s,
            data: e,
            success: function(a) {
                var e = a.data;
                1 == e.result && t.setData({
                    info: e.data,
                    isLoadMore: !0,
                    total_page: e.data.poster_list.last_page
                });
            }
        });
    },
    getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.page = this.page + 1, this.setData({
                page: Number(this.data.page) + 1
            });
            var e = {
                page: this.page,
                poster_type: this.data.active ? this.data.active : "",
                title: this.data.keywork,
                label_id: this.data.labelSelect ? this.data.labelSelect : ""
            }, s = a.getNetAddresss("plugin.poster-center.frontend.controllers.index.index");
            a._getNetWork({
                url: s,
                data: e,
                success: function(a) {
                    var e = a.data;
                    if (console.log(e), 1 == e.result) {
                        var s = e.data.poster_list.data;
                        t.data.info.poster_list.data = t.data.info.poster_list.data.concat(s), t.data.isLoadMore = !0, 
                        t.setData({
                            info: t.data.info,
                            total_page: e.data.poster_list.last_page
                        });
                    }
                }
            });
        }
    }
});